<?   
$GLOBALS['table_model']['nosorting']=1;
if($GLOBALS['noremove']) {
	$GLOBALS['table_model']['noremove']=1;
}
if($table['tablehead'])
  {
      $havesorting='';
	  //// <!--▼▼ remove sorting first field if no sorting 01/02/2016 13:35 by william ▼▼--> 
	  foreach($table['tablehead'] as $key => $value)
      {
		  if(have(remove_html($value),'sorting')){
			  $havesorting = 1;
		  }
	  }
	  
	  if(!$havesorting) {
		  $GLOBALS['table_model']['nosorting']=1;
	  }
  }?>

<!--▼▼for tableaddon▼▼--><style>
table.dt-rowReorder-float{position:absolute !important;opacity:0.8;table-layout:static;outline:2px solid #888;outline-offset:-2px;z-index:2001}tr.dt-rowReorder-moving{outline:2px solid #555;outline-offset:-2px}body.dt-rowReorder-noOverflow{overflow-x:hidden}table.dataTable td.reorder{text-align:center;cursor:move}
</style>

<!-- END GLOBAL MANDATORY STYLES -->
<!-- BEGIN PAGE LEVEL PLUGINS -->
<link href="assets/global/plugins/datatables/datatables.min.css" rel="stylesheet" type="text/css" />
<link href="assets/global/plugins/datatables/plugins/bootstrap/datatables.bootstrap.css" rel="stylesheet" type="text/css" />
<!-- END PAGE LEVEL PLUGINS -->
<!-- BEGIN THEME GLOBAL STYLES -->
<link href="assets/global/css/plugins.min.css" rel="stylesheet" type="text/css" />
<!-- END THEME GLOBAL STYLES -->        

<? echo $GLOBALS['table_model_add1'] ; ?>

<form method="post" class="col-md-12">
<? echo $GLOBALS['table_model_add2'] ; ?>
<table class="table table-striped table-bordered table-hover table-checkable order-column " id="<? echo $tableid_set ; ?>table" style="text-align: center">

  <thead>
  <tr><!--▼▼
      <th class="table-checkbox">
          <input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"/>
      </th>▼▼-->
      <? if(!$GLOBALS['table_model']['nosorting']) {
		  echo '<th style="width:5px;" style="text-align: center"></th>';
		  $addstyle = 'right:8px; ';
	  }?>
      
     <? 
     if($table['tablehead']):?>
     
		 <? 
		 // for no remove 
		 if(!$GLOBALS['table_model']['noremove']) {
         ?>
            <th class="table-checkbox" style="text-align: center">
            	<div style="  <? echo $addstyle ; ?>  position: relative;"><input type="checkbox" class="group-checkable" data-set=".checkboxes"  /></div>
            </th>
         <? } ?>
      
     
          <? foreach( $table['tablehead'] as $key => $value): ?>
              <th style="text-align: center">
                   <? echo $value ; ?>
              </th>
          <? endforeach; ?>
      <? endif; ?>

      <th>&nbsp;</th>
  </tr>
  </thead>
  <tbody>
  
  <? 
  if($table['table_data_line'])
  {
      $table_data_line = $table['table_data_line'];
      $table_action = $table['table_action'];
      $table_id = $table['id_list'];
	  $line = '';

	  
      foreach($table['table_data_line'] as $key => $value)
      { 
      
          ?>
      <tr class="odd gradeX" data-position="<? echo $table_id[$key] ; ?>" id="<? echo $table_id[$key] ; ?>">
      <? if(!$GLOBALS['table_model']['nosorting']) { ?>      
      <td><i class="fa fa-arrows-v" style="color:#CCC"></i></td>
      <? } ?>
<!--▼▼				<td>
              <input type="checkbox" class="checkboxes" value="1"/>
          </td>▼▼-->
     <? if(!$GLOBALS['table_model']['noremove']) { ?>
			<td data-id="<? echo $table_id ; ?>"><input type="checkbox" name="select_id[]" class="checkboxes" value="<? echo $table_id[$key] ; ?>" /></td>
      <? } ?>
               
      
	  <? foreach( $table_data_line[$key] as  $datavalue): ?>
          <td>
              <? 
			  echo $datavalue ;
			   ?>
          </td>
      <? endforeach; ?>
      
      <? if($table_sorting): ?>
          <td>
              - <input type="text" value="" name="" style="width:10px;" /> +
          </td>	
      <? endif; ?>
          
          <td>
          <? 
		  if($GLOBALS['listdata'][$key]['modellink']) {
			  ?>
                  <div style="margin-bottom:5px;">
                  <a class="btn default btn-xs blue" href="<? echo $GLOBALS['listdata'][$key]['modellink'] ; ?>">
                  <i class="fa fa-edit"></i> <? echo $GLOBALS['listdata'][$key]['modellink_name'] ; ?> </a>
                  </div>
              <?
		  }
		  
		  if($GLOBALS['listdata'][$key]['nobtn']) {
			  //skip
		  }else{
	
			  if($table_action[$key]['name']):
				  foreach( $table_action[$key]['name'] as $but_i => $butname_arr): 
					  $actionlink = $table_action[$key]['link'][$but_i] ;
					  $actionname = $butname_arr;
					  ?>
					  <div style="margin-bottom:5px;">
						  
						  <? if($butname_arr=='Edit'): ?>
							  <a class="btn default btn-xs purple" href="<? echo $actionlink ; ?>">
							  <i class="fa fa-edit"></i> <? echo $actionname ; ?> </a>
						  <? elseif($butname_arr=='Remove' ): ?>
							  <a class="btn btn-danger btn-xs black" 
		data-toggle="confirmation" data-placement="top"  data-btn-cancel-label="No" data-btn-cancel-icon="icon-close" data-btn-cancel-class="btn-danger" data-btn-ok-label="Yes" data-btn-ok-icon="icon-like" data-btn-ok-class="btn-success" data-original-title="" title="" href="<? echo $actionlink ; ?>" data-href="<? echo $actionlink ; ?>" 
									   >
									   
		<? /*
							  <a href="#" class="btn btn-danger btn-xs black" 
									  onClick="conf('<? echo $actionlink ; ?>')">*/ ?>                               
							  <i class="fa fa-trash-o"></i> <? echo $actionname ; ?> </a>
							  
		
						  <? else: //d('sadadadsadasda');?>                                            
							  <a class="btn btn-info btn-xs " href="<? echo $actionlink ; ?>">
							   <? echo $actionname ; ?> </a>
						  <? endif; ?>
					  </div>
					  
				  <? endforeach; 
			  endif;		  
		  }
?>
          </td>
      </tr>
      <? } 
  }?>
  
  </tr>
  </tbody>
</table>

<br />


<? if(!$GLOBALS['table_model']['noremove']) { ?>
	<button type="submit" class="btn btn-danger" data-toggle="confirmation" data-placement="top" data-btn-ok-label="Yes" data-btn-ok-icon="icon-like" data-btn-ok-class="btn-success" data-btn-cancel-label="No" data-btn-cancel-icon="icon-close" data-btn-cancel-class="btn-danger" data-original-title="" title=""> <i class="fa fa-times"></i> Remove Selected Items </button>
<? } ?>
<br /><br />
</form>





        <!--[if lt IE 9]>
<script src="assets/global/plugins/respond.min.js"></script>
<script src="assets/global/plugins/excanvas.min.js"></script> 
<![endif]-->
        <!-- BEGIN CORE PLUGINS -->
        <!-- BEGIN PAGE LEVEL PLUGINS -->
        <script src="assets/global/scripts/datatable.js" type="text/javascript"></script>
        <script src="assets/global/plugins/datatables/datatables.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/datatables/plugins/bootstrap/datatables.bootstrap.js" type="text/javascript"></script>
        <!-- END PAGE LEVEL PLUGINS -->
        <script src="assets/global/plugins/bootstrap-confirmation/bootstrap-confirmation.min.js" type="text/javascript"></script>
        <script src="assets/pages/scripts/ui-confirmations.min.js" type="text/javascript"></script>
        <!-- BEGIN THEME GLOBAL SCRIPTS -->
        <script src="assets/global/scripts/app.min.js" type="text/javascript"></script>
        <!-- END THEME GLOBAL SCRIPTS -->

<script src="library/js/table/tableaddon.js"></script>
        


<script>

$(document).ready(function() {

var TableDatatablesManaged = function () {

    var initTable1 = function () {

        var table = $('#<? echo $tableid_set ; ?>table');

        // begin first table
        var oTable = table.dataTable({
			<? /*"ajax": '<? echo url_update('','ajax_data','1') ; ?>',*/ ?>
			
            // Internationalisation. For more info refer to http://datatables.net/manual/i18n
            "language": {
                "aria": {
                    "sortAscending": ": activate to sort column ascending",
                    "sortDescending": ": activate to sort column descending"
                },
                "emptyTable": "No data available in table",
                "info": "Showing _START_ to _END_ of _TOTAL_ records",
                "infoEmpty": "No records found",
                "infoFiltered": "(filtered1 from _MAX_ total records)",
                "lengthMenu": "Show _MENU_",
                "search": "Search:",
                "zeroRecords": "No matching records found",
                "paginate": {
                    "previous":"Prev",
                    "next": "Next",
                    "last": "Last",
                    "first": "First"
                }
            },

            // Or you can use remote translation file
            //"language": {
            //   url: '//cdn.datatables.net/plug-ins/3cfcc339e89/i18n/Portuguese.json'
            //},

            // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
            // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js). 
            // So when dropdowns used the scrollable div should be removed. 
            //"dom": "<'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
            /*
            "dom": "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable 
            */
            "bStateSave": false, // save datatable state(pagination, sort, etc) in cookie.
			
            "buttons": [
                { extend: 'print', className: 'btn dark btn-outline' ,
                                                                                        exportOptions: {
                                                                                            columns: ':visible'
                                                                                        }
                                                                    },
                { extend: 'copy', className: 'btn red btn-outline' ,
                                                                                        exportOptions: {
                                                                                            columns: ':visible'
                                                                                        }
                                                                    },
                { extend: 'pdf', className: 'btn green btn-outline' ,
                                                                                        exportOptions: {
                                                                                            columns: ':visible'
                                                                                        }
                                                                    },
                { extend: 'excel', className: 'btn yellow btn-outline ' ,
                                                                                        exportOptions: {
                                                                                            columns: ':visible'
                                                                                        }
                                                                    },
                { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
            ],
            "columnDefs": [ {
                targets: -1,
                visible: false
            } ],
            
			bFilter: false, bInfo: false,
			"paging": false,
            /*
            "columnDefs": [ {
                "targets": 0,
                "orderable": false,
                "searchable": false
            }],
            */

            "lengthMenu": [
                [20, 100, 500, -1],
                [20, 100, 500, "All"] // change per page values here
            ],
            // set the initial value
            "pageLength": 100,            
            "pagingType": "bootstrap_full_number",
            "columnDefs": [{  // set default column settings
                'orderable': false,
                'targets': [0]
            }, {
                "searchable": false,
                "targets": [0]
            }],
            "order": [
                [0, "asc"]
            ] // set first column as a default sort by asc
            ,
            "ordering": false,
			<? if(!$GLOBALS['table_model']['nosorting']) {
?>
			rowReorder: true,
			<? } ?>
			bJQueryUI: true,
            
            
        });

        var tableWrapper = jQuery('#sample_1_wrapper');

//<!--▼▼check▼▼-->
        table.find('.group-checkable').change(function () {

            var set = jQuery(this).attr("data-set");
            var checked = jQuery(this).is(":checked");
            jQuery(set).each(function () {
                if (checked) {
                    $(this).prop("checked", true);
                    $(this).parents('tr').addClass("active");
                } else {
                    $(this).prop("checked", false);
                    $(this).parents('tr').removeClass("active");
                }
            });
            jQuery.uniform.update(set);
        });

        table.on('change', 'tbody tr .checkboxes', function () {
            $(this).parents('tr').toggleClass("active");
        })
		
		return table;
		
    }



    return {

        //main function to initiate the module
        init: function () {
            if (!jQuery().dataTable) {
                return;
            }

            return initTable1();
        }

    };

}();


    jQuery(document).ready(function() {
        table = TableDatatablesManaged.init();
 
			table.on( 'row-reorder.dt', function ( e, diff, edit ) {
				var result='';
				for ( var i=0, ien=diff.length ; i<ien ; i++ ) {
//					console.log(edit.nodes[i].id +' : ' + diff[i].oldPosition + '  >  ' + diff[i].newPosition  );
		
					result += '&changid[]='+edit.nodes[i].id+'&changefrom[]='+diff[i].oldPosition+'&changeto[]='+diff[i].newPosition;
		
				}
				
				conf('<? echo url() ; ?>'+result);
			} );
			
    });


} );


</script>
    
    